package cn.elead.chaos.remote.web.system.controller;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.elead.chaos.core.enums.BusinessType;
import cn.elead.chaos.excel.ExcelUtil;
import cn.elead.chaos.framework.monitor.operlog.Log;
import cn.elead.chaos.mybatils.web.controller.BaseController;
import cn.elead.chaos.mybatils.web.page.TableDataInfo;
import cn.elead.chaos.remote.web.system.domain.SysNotice;
import cn.elead.chaos.remote.web.system.service.IRemoteNoticeService;

/**
 * 通知公告Controller
 * 
 * @author luopeng
 * @date 2020-02-26 18:40:26
 */
@RestController
@RequestMapping("/remote/system/notice")
public class RemoteNoticeController extends BaseController
{
    @Autowired
    private IRemoteNoticeService noticeService;

    /**
     * 查询通知公告列表
     */
    @GetMapping("/page")
    @RequiresPermissions("system:notice:list")
    public TableDataInfo<SysNotice> page(SysNotice sysNotice) {
        return noticeService.page(sysNotice);
    }
    

    /**
     * 导出通知公告列表
     */
    @GetMapping("/export")
    @RequiresPermissions("system:notice:export")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    public String export(SysNotice sysNotice) {
        List<SysNotice> list = noticeService.list(sysNotice);
        ExcelUtil<SysNotice> util = new ExcelUtil<SysNotice>(SysNotice.class);
        return util.exportExcel(list, "notice");
    }

    /**
     * 获取通知公告详细信息
     */
    @GetMapping(value = "/{noticeId}") 
    @RequiresPermissions("system:notice:query")
    public SysNotice getInfo(@PathVariable("noticeId") Integer noticeId) {
       	return noticeService.getInfo(noticeId);
    }

    /**
     * 新增通知公告
     */
    @PostMapping
    @RequiresPermissions("system:notice:add")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    public int add(@RequestBody SysNotice sysNotice) {
    	return noticeService.add(sysNotice);
    }

    /**
     * 修改通知公告
     */
    @PutMapping
    @RequiresPermissions("system:notice:edit")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    public int edit(@RequestBody SysNotice sysNotice) {
        return noticeService.edit(sysNotice);
    }

    /**
     * 删除通知公告
     */
	@DeleteMapping("/{noticeId}")
    @RequiresPermissions("system:notice:remove")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    public int remove(@PathVariable Long noticeId){
        return noticeService.remove(noticeId);
    }
}